/*
 * @Author: yangzonglong
 * @Date: 2021-03-08 15:27:24
 * @version: v1.0.0
 * @Descripttion:
 * @LastEditors: 871387321@qq.com 871387321@qq.com
 * @LastEditTime: 2023-11-09 16:43:27
 * @Auditor:
 */
import React from 'react';
import { Form, Checkbox } from 'antd';
import FormItemController from './../components/FormItemController';
import OptionSetting from '../components/optionSetting/OptionSetting';
import useControlOptions from '../../hooks/useControlOptions';
import { SelectProps } from './Select';

const Controller = () => {
  const { options, changeFormItemProps, changeControlProps } = useControlOptions<SelectProps>('selectProps');

  return (
    <FormItemController
      onChange={changeFormItemProps}
      placeholder={options?.selectProps?.placeholder as string}
      placeholderEn={options?.selectProps?.placeholderEn}
      onChangePlaceholder={(e) =>
        changeControlProps(
          'selectProps',
          {
            ...options?.selectProps,
            placeholder: e,
          },
          true
        )
      }
      onChangePlaceholderEn={(e) =>
        changeControlProps(
          'selectProps',
          {
            ...options?.selectProps,
            placeholderEn: e,
          },
          true
        )
      }
      options={options?.formItemProps}
    >
      <OptionSetting editInModal showDefault otherProps="selectProps" changeControlProps={(propsKey, value, flag) => {
        changeControlProps('selectProps', {
          ...value,
          defaultValue: value?.dataSource?.filter((item: any) => item.checked)?.[0]?.value
        }, flag);
      }} options={options?.selectProps} />

      <Form.Item className="antd-form-item-row" label='多选'>
        <Checkbox onChange={(e) => {
          changeControlProps(
            'selectProps',
            {
              ...options?.selectProps,
              checkbox: e.target.checked
            },
            true
          )
        }} checked={options?.selectProps?.checkbox} />
      </Form.Item>
    </FormItemController>
  );
};

export default Controller;
